package com.xunqi.usercenter.controller;

import com.xunqi.common.dto.user.UserAddBonseDTO;
import com.xunqi.common.dto.user.UserAddBonusMsgDTO;
import com.xunqi.common.entity.user.User;
import com.xunqi.usercenter.service.UserService;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @Description:
 * @Created with IntelliJ IDEA.
 * @author: 夏沫止水
 * @create: 2020-04-17 16:10
 **/
@RestController
@RequestMapping(value = "/users")
public class BonusController {

    @Resource
    private UserService userService;

    @RequestMapping(value = "/add-bonus")
    public User addBonus(@RequestBody UserAddBonseDTO userAddBonseDTO) {

        Integer userId = userAddBonseDTO.getUserId();

        userService.addBonus(
                UserAddBonusMsgDTO.builder()
                        .userId(userId)
                        .bonus(userAddBonseDTO.getBonus())
                        .description("兑换分享")
                        .event("BUY")
                        .build()
        );
        return this.userService.findById(userId);
    }

}
